﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace WOS.Windows
{
    class WindowsCommands
    {
        public void BilgisariKapat()
        {
            System.Diagnostics.Process.Start(@"C:\WINDOWS\System32\shutdown.exe" , "-s");
        }
        public void Restart()
        {
            System.Diagnostics.Process.Start(@"C:\WINDOWS\System32\shutdown.exe", "-r");
        }
        public void CompressZip(string sPath)
        {
            ZipOutputStream zipOut = new ZipOutputStream(File.Create(@"C:\test.zip"));
            foreach (string fName in Directory.GetFiles(sPath))
            {
                FileInfo fi = new FileInfo(fName);
                ZipEntry entry = new ZipEntry(fi.Name);
                FileStream sReader = File.OpenRead(fName);
                byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
                sReader.Read(buff, 0, (int)sReader.Length);
                entry.DateTime = fi.LastWriteTime;
                entry.Size = sReader.Length;
                sReader.Close();
                zipOut.PutNextEntry(entry);
                zipOut.Write(buff, 0, buff.Length);
            }
            zipOut.Finish();
            zipOut.Close();
            Console.WriteLine("Done!!");
        }
        public void UncompressZip(string sFile)
        {
            ZipInputStream zipIn = new ZipInputStream(File.OpenRead(sFile));
            ZipEntry entry;
            while ((entry = zipIn.GetNextEntry()) != null)
            {
                FileStream streamWriter = File.Create(@"C:\" + entry.Name);
                long size = entry.Size;
                byte[] data = new byte[size];
                while (true)
                {
                    size = zipIn.Read(data, 0, data.Length);
                    if (size > 0) streamWriter.Write(data, 0, (int)size);
                    else break;
                }
                streamWriter.Close();
            }
            Console.WriteLine("Done!!");
        }  
    }
}
